package Views.Base;


import Views.*;
import java.awt.*;
import javax.swing.*;

/**
 *
 * @author Joshua King
 */
public abstract class BaseViewMain extends JFrame {

    protected ViewGeneralBar westGeneralPanel = new ViewGeneralBar();
    //protected ViewUserBar westUserPanel = new ViewUserBar();
    //protected ViewManBar westManPanel = new ViewManBar();
    protected JPanel bottomPanel = new JPanel();
    protected ViewLoginBar northLoginPanel = new ViewLoginBar();
    protected ViewLogoutUser logoutPanel = new ViewLogoutUser();
    protected ViewCreateUser createUserPanel = GUIFactory.makeViewCreateUser();
    //protected ViewDeleteUser deleteUserPanel = GUIFactory.makeViewDeleteUser();
    protected ViewUpdate updatePanel = GUIFactory.makeViewUpdate();
    protected ViewDeleteConfirm deleteConfirmFrame = GUIFactory.makeViewDeleteConfirm();
    private BorderLayout layout = new BorderLayout();

    /**
     * The constructor initialises main panels
     */
    public BaseViewMain() {
        setLayout(layout);
        setNorthPanel(northLoginPanel);
        setWestPanel(westGeneralPanel);
        add(bottomPanel, BorderLayout.SOUTH);
        setSize(new Dimension(800, 400));
        setTitle("Flights");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        validate();
        setVisible(true);
    }

    /**
     * It removes the component that is located in the border layout centre area
     */
    public void setCenterPanel(Component comp) {
        if (layout.getLayoutComponent(BorderLayout.CENTER) != null) {
            layout.getLayoutComponent(BorderLayout.CENTER).setVisible(false);
            remove(layout.getLayoutComponent(BorderLayout.CENTER));
        }
        add(comp, BorderLayout.CENTER);
        layout.getLayoutComponent(BorderLayout.CENTER).setVisible(true);
        validate();
    }

    public void setNorthPanel(Component comp) {
        if (layout.getLayoutComponent(BorderLayout.NORTH) != null) {
            layout.getLayoutComponent(BorderLayout.NORTH).setVisible(false);
            remove(layout.getLayoutComponent(BorderLayout.NORTH));       
        }
        add(comp, BorderLayout.NORTH);
        layout.getLayoutComponent(BorderLayout.NORTH).setVisible(true);
        validate();
    }
    
    public void setWestPanel(Component comp) {
        if (layout.getLayoutComponent(BorderLayout.WEST) != null) {
            layout.getLayoutComponent(BorderLayout.WEST).setVisible(false);
            remove(layout.getLayoutComponent(BorderLayout.WEST));         
        }
        getContentPane().add(comp, BorderLayout.WEST);
        layout.getLayoutComponent(BorderLayout.WEST).setVisible(true);
        validate();       
    }
}
